use "${data}IndirectSurveyDataReplication.dta", clear

egen cut_num_ejid = cut(num_ejidatarios), group(3)
la var soc_cap_simple "Social capital index"
************************DIFFERENCES ************************

foreach x in adijefe_secondaria  adiparedes_vivienda aditelevision adicoche aditel_movil adicuidado_bosque adipersonas_hogar adinum_ganado_mayor {
//leader characteristics//educ interaction
reg `x' num_ejidatarios_IHS, cluster(ejnclnmid)
eststo networks`x'

reg `x' meancarg, cluster(ejnclnmid)
eststo elite`x'
reg `x' soc_cap_simple, cluster(ejnclnmid)
eststo sc`x'
reg `x' lider_educ lider_edad, cluster(ejnclnmid)
eststo educ`x'
reg `x' num_ejidatarios_IHS meancarg soc_cap_simple lider_educ lider_edad, cluster(ejnclnmid)
eststo all`x'

xi: reg `x' i.cut_num_ejid, cluster(ejnclnmid)

}


esttab networks*  ///
	using "${outputs}social_capitaldif.tex",  ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "" "" "" ""  ) ///
	 keep(num_ejidatarios_IHS) nonumbers  replace  fragment  ///
	prehead( { \begin{tabular}{lcccccccc} \hline \hline ///
	 & Sec. sch. & Walls & Television & Car & Mobile &  Forest wk. & HH size & Cattle \\ ///
	 & (0/1) & (0/1) & (0/1) & (0/1) & (0/1) &(0/1) &  (num.) & (num.)  \\ \hline ) ///
	 posthead(A: Ejido size & \\ [1em]) ///

esttab elite*  ///
	using "${outputs}social_capitaldif.tex",  ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "" "" "" "" ) ///
	 keep(meancarg)  nonumbers  append  fragment ///
	 posthead(\hline B: Leadership capture & \\  [1em]) 

esttab sc*  ///
	using "${outputs}social_capitaldif.tex",  ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "" "" "" "" ) ///
	 keep(soc_cap_simple)  nonumbers  append  fragment ///
	 posthead(\hline C: Trust &  \\ [1em] ) 

	 
esttab educ*  ///
	using "${outputs}social_capitaldif.tex",  ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "" "" "" "" ) ///
	 keep(lider_educ lider_edad)  nonumbers  append  fragment ///
	 posthead(\hline D: Education/age &  \\ [1em] ) 


esttab all* ///
	using "${outputs}social_capitaldif.tex", append ///
	keep( num_ejidatarios_IHS meancarg soc_cap_simple lider_edad lider_educ) ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  fragment  nonumbers ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "" "" "" ""  ) ///
	 posthead(\hline E: All &  \\ [1em]) ///
	 prefoot( \hline \hline ) ///
	postfoot(\hline \hline \end{tabular} } \begin{tablenotes}[para,flushleft] \tiny{Notes: Regressors are the absolute value of the difference  ///
	between the leader and household report of the same measure.  Standard errors are clustered at the ejidal level and regressions are simple OLS ///
	with a constant. All panels contain only the covariates reported and a constant. } \end{tablenotes} )

preserve	
******************** ONLY FOR THOSE WHICH HAVE ALL NON-MISSINGS *********************
reg IPW_HH IPW_leader
keep if e(sample)
estimates clear

foreach x in adijefe_secondaria  adiparedes_vivienda aditelevision adicoche aditel_movil adicuidado_bosque adipersonas_hogar adinum_ganado_mayor {
//leader characteristics//educ interaction
reg `x' num_ejidatarios_IHS, cluster(ejnclnmid)
eststo networks`x'
reg `x' meancarg, cluster(ejnclnmid)
eststo elite`x'
reg `x' soc_cap_simple, cluster(ejnclnmid)
eststo sc`x'
reg `x' lider_educ lider_edad, cluster(ejnclnmid)
eststo educ`x'
reg `x' num_ejidatarios_IHS meancarg soc_cap_simple lider_educ lider_edad, cluster(ejnclnmid)
eststo all`x'

sum `x'
scalar mn = r(mean)
estadd scalar mn


}

esttab networks*  ///
	using "${outputs}social_capitaldif_nonmissing.tex",  ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "" "" "") ///
	 keep(num_ejidatarios_IHS) nonumbers  replace  fragment  ///
	prehead( { \begin{tabular}{lcccccccc} \hline \hline ///
	 & Sec. sch. & Walls & Television & Car & Mobile &  Forest wk. & HH size & Cattle  \\ ///
	 & (0/1) & (0/1) & (0/1) & (0/1) & (0/1) &(0/1) &  (num.) & (num.) \\ \hline ) ///
	 posthead(A: Ejido size & \\ [1em]) ///

esttab elite*  ///
	using "${outputs}social_capitaldif_nonmissing.tex",  ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "" "" "" ) ///
	 keep(meancarg)  nonumbers  append  fragment ///
	 posthead(\hline B: Leadership capture & \\  [1em]) 

esttab sc*  ///
	using "${outputs}social_capitaldif_nonmissing.tex",  ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "" "" "" ) ///
	 keep(soc_cap_simple)  nonumbers  append  fragment ///
	 posthead(\hline C: Trust &  \\ [1em] ) 

	 
esttab educ*  ///
	using "${outputs}social_capitaldif_nonmissing.tex",  ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "" "" "" ) ///
	 keep(lider_educ lider_edad)  nonumbers  append  fragment ///
	 posthead(\hline D: Education/age &  \\ [1em] ) 


esttab all* ///
	using "${outputs}social_capitaldif_nonmissing.tex", append ///
	keep( num_ejidatarios_IHS meancarg soc_cap_simple lider_edad lider_educ) ///
	se nonotes  nonumbers  style(tex)  b(%12.3f) se(%12.3f) fragment scalars("mn Mean dep. var.") ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "" "" "" ) ///
	 posthead(\hline E: All &  \\ [1em]) ///
	 prefoot( \hline \hline ) ///
	postfoot(\hline \hline \end{tabular} } \begin{tablenotes}[para,flushleft] \footnotesize{Notes: Regressors are the absolute value of the difference  ///
	between the leader and household report of the same measure.  Standard errors are clustered at the ejidal level and regressions are simple OLS ///
	with a constant. Only observations with all variables non-missing are included.} \end{tablenotes} )

estimates clear

foreach x in difjefe_secondaria  difparedes_vivienda diftelevision difcoche diftel_movil difcuidado_bosque difpersonas_hogar difnum_ganado_mayor {
reg `x' num_ejidatarios_IHS, cluster(ejnclnmid)
eststo networks`x'
reg `x' meancarg, cluster(ejnclnmid)
eststo elite`x'
reg `x' soc_cap_simple, cluster(ejnclnmid)
eststo sc`x'
reg `x' lider_educ lider_edad, cluster(ejnclnmid)
eststo educ`x'
reg `x' num_ejidatarios_IHS meancarg soc_cap_simple lider_educ lider_edad, cluster(ejnclnmid)
eststo all`x'

sum `x'
scalar mn = r(mean)
estadd scalar mn

	}
	

esttab networks*  ///
	using "${outputs}misreporting.tex",  ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "" "" "") ///
	 keep(num_ejidatarios_IHS) nonumbers  replace  fragment  ///
	prehead( { \begin{tabular}{lcccccccc} \hline \hline ///
	 & Sec. sch. & Walls & Television & Car & Mobile &  Forest wk. & HH size & Cattle  \\ ///
	 & (0/1) & (0/1) & (0/1) & (0/1) & (0/1) &(0/1) &  (num.) & (num.) \\ \hline ) ///
	 posthead(\multicolumn{2}{l}{A: Community membership size } & \\ [1em]) ///

esttab elite*  ///
	using "${outputs}misreporting.tex",  ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "" "" "" ) ///
	 keep(meancarg)  nonumbers  append  fragment ///
	 posthead(\hline B: Leadership capture & \\  [1em]) 

esttab sc*  ///
	using "${outputs}misreporting.tex",  ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "" "" "" ) ///
	 keep(soc_cap_simple)  nonumbers  append  fragment ///
	 posthead(\hline C: Social capital &  \\ [1em] ) 

	 
esttab educ*  ///
	using "${outputs}misreporting.tex",  ///
	se nonotes  style(tex)  b(%12.3f) se(%12.3f)  noobs ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "" "" "" ) ///
	 keep(lider_educ lider_edad)  nonumbers  append  fragment ///
	 posthead(\hline D: Education/age &  \\ [1em] ) 


esttab all* ///
	using "${outputs}misreporting.tex", append ///
	keep( num_ejidatarios_IHS meancarg soc_cap_simple lider_edad lider_educ) ///
	se nonotes  nonumbers  style(tex)  b(%12.3f) se(%12.3f) fragment scalars("mn Mean dep. var.") ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "" "" "" ) ///
	 posthead(\hline E: All &  \\ [1em]) ///
	 prefoot( \hline \hline ) ///
	postfoot(\hline \hline \end{tabular} } \begin{tablenotes}[para,flushleft] \footnotesize{Notes: Regressors are the value of the difference  ///
	between the leader and household report of the same measure. Positive values indicate leader values greater than household values. ///
	Standard errors are clustered at the community level and regressions are simple OLS ///
	with a constant. Only observations with all variables non-missing are included.* p $<$.10, ** p$<$ .05, *** p$<$.01.} \end{tablenotes} )
		
	
	restore
